/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mail;

import java.io.File;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.faces.bean.ApplicationScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletContext;

/**
 *
 * @author damfercer
 */
@Named
@ApplicationScoped
public class EmailTemplateHelper implements Serializable{
    @Inject
    EmailEJB emailEJB;
    public static final String logoId="<logo>";
    public static final String facesId="<faces>";
    public static final String facesSearchId="<facesSearch>";
    
    public static ResourceBundle getMessages(){
        FacesContext context = FacesContext.getCurrentInstance();
        Locale locale=context.getViewRoot().getLocale();
        ResourceBundle rb = ResourceBundle.getBundle("messages", locale);
        return rb;
    }    
    
   public static String getHtmlHeader(){
        StringBuilder sb=new StringBuilder();
        sb.append("<div style=\"padding-bottom:15px;\"><a href=http://www.therecruitery.com><img src=\"cid:logo\"></img></a></div>");
        return sb.toString();
    }
    
    public static String getHtmlSearchFaces(){
        StringBuilder sb=new StringBuilder();
        sb.append("<div style=\"padding-bottom:15px;\"><a href=http://www.therecruitery.com><img style=\"width:500px;\" src=\"cid:facesSearch\"></img></a></div>");
        return sb.toString();
    }
    
    public static String getHtmlDivText(String text){
        StringBuilder sb=new StringBuilder();
        sb.append("<div style=\"padding-bottom:10px;\"><span style=\"font-family:Arial,Helvetica,sans-serif;font-size:13px;color:#868585;margin:0;padding:0;line-height:1.6em\">");
        sb.append(text);
        sb.append("</span></div>");
        return sb.toString();
    }

    
    public static String getHtmlFacesBody(){
        StringBuilder sb=new StringBuilder();
        sb.append("<div style=\"padding-bottom:25px;\"><img src=\"cid:faces\"></img></div>");
        return sb.toString();
    }
    


     
    public static String getSocialNetworkFooter(){
        StringBuilder sb=new StringBuilder();
        sb.append("<div style=\"padding-bottom:15px;\">");
        sb.append("<a href='http://www.facebook.com/TheRecruitery' style=\"font-family:Arial,Helvetica,sans-serif;font-size:13px;color:#868585;margin:0;padding:0;line-height:1.6em\">");
        sb.append("Facebook");
        sb.append("</a>");
        sb.append("   ");
        sb.append("<a href='http://www.twitter.com/TheRecruitery' style=\"font-family:Arial,Helvetica,sans-serif;font-size:13px;color:#868585;margin:0;padding:0;line-height:1.6em\">");
        sb.append("Twitter");
        sb.append("</a>");
        sb.append("   ");
        sb.append("<a href='http://www.linkedin.com/company/therecruitery' style=\"font-family:Arial,Helvetica,sans-serif;font-size:13px;color:#868585;margin:0;padding:0;line-height:1.6em\">");
        sb.append("LinkedIn");
        sb.append("</a>");
        sb.append("</div>");
        return sb.toString();
    }
    
    public static DataSource getFileDataSourceFromURL(URL url) throws URISyntaxException{
        File emailImage = new File(url.toURI());  
        DataSource fds = new FileDataSource(emailImage);
        return fds;
    }  
    
    public static DataSource getFileDataSource(String relativePath){
        ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
        String contextPath = servletContext.getRealPath("/");
        File contextDir = new File(contextPath);  
        File emailImage = new File(contextDir, relativePath);  
        DataSource fds = new FileDataSource(emailImage);
        return fds;
    }
}
